﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace SVAccountingBL
{
    [DataObject(true)]
    public class FinantialCardODS
    {
        

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static List<FinancialCard> GetAllFinatialCards()
        {
            SVALinqDataContext db = new SVALinqDataContext();

             

            List<FinancialCard> finantialCard = new List<FinancialCard>();

            List<FinancialCard> fcards = (from f in db.FinancialCards
                                          select f).ToList();
            return fcards;
        }

        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static void UpdateFinantialCardInfo(FinancialCard theCard)
        {
            SVALinqDataContext db = new SVALinqDataContext();


            FinancialCard tempCard = db.FinancialCards.Single(p => p.CardId == theCard.CardId);
            tempCard.ComintenttAccountID = theCard.ComintenttAccountID;
            tempCard.OwnerAccountID = theCard.OwnerAccountID;
            tempCard.Debit = theCard.Debit;
            tempCard.Credit = theCard.Credit;
            tempCard.CreatorId = theCard.CreatorId;

            db.SubmitChanges();
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static List<Person> GetFinantialCardsCreators()
        {
            SVALinqDataContext db = new SVALinqDataContext();

            List<Person> p = (from t in db.Persons
                    where
                        (from t0 in db.rAccountantPersons
                         select new
                         {
                             t0.PersonID
                         }).Contains(new { t.PersonID })
                    select t).ToList();

            return p;
        }
    }
}
